/*   1:    */ package com.jetbrains.licenseService.util;
/*   2:    */ 
/*   3:    */

import org.jetbrains.annotations.NotNull;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

/*   4:    */
/*   5:    */
/*   6:    */ 
/*   7:    */ public class RSAEncoder
/*   8:    */ {
/*   9:    */   private final BigInteger a;
/*  10:    */   private final BigInteger b;
/*  11:    */   private final int c;
/*  12:    */   private final int d;
/*  13:    */   private final BigInteger e;
/*  14:    */   
/*  15:    */   public RSAEncoder(BigInteger paramBigInteger1, BigInteger paramBigInteger2)
/*  16:    */   {
/*  17: 16 */     this(paramBigInteger1, paramBigInteger2, 16);
/*  18:    */   }
/*  19:    */   
/*  20:    */   protected RSAEncoder(BigInteger paramBigInteger1, BigInteger paramBigInteger2, int paramInt)
/*  21:    */   {
/*  22: 20 */     this.a = paramBigInteger1;
/*  23: 21 */     this.b = paramBigInteger2;
/*  24: 22 */     int i = paramBigInteger2.bitLength();
/*  25: 23 */     this.e = new BigInteger(String.valueOf(paramInt));
/*  26: 24 */     this.c = (i / 8 - 1);
/*  27: 25 */     int j = (int)Math.ceil(i / Math.log(paramInt) * Math.log(2.0D));
/*  28: 26 */     if (j % 5 != 0) {
/*  29: 27 */       j = (j / 5 + 1) * 5;
/*  30:    */     }
/*  31: 29 */     this.d = j;
/*  32:    */   }
/*  33:    */   
/*  34:    */   public String encodeString(String paramString)
/*  35:    */   {
/*  36:    */     try
/*  37:    */     {
/*  38: 34 */       return encode(paramString.getBytes("UTF-8"));
/*  39:    */     }
/*  40:    */     catch (UnsupportedEncodingException localUnsupportedEncodingException) {}
/*  41: 38 */     return "";
/*  42:    */   }
/*  43:    */   
/*  44:    */   public String encode(byte[] paramArrayOfByte)
/*  45:    */   {
/*  46: 43 */     StringBuilder localStringBuilder = new StringBuilder();
/*  47:    */     
/*  48: 45 */     byte[] arrayOfByte1 = paramArrayOfByte.length % this.c;
/*  49: 46 */     if (arrayOfByte1 > 0)
/*  50:    */     {
/*  51: 47 */       arrayOfByte2 = new byte[this.c];
/*  52: 48 */       System.arraycopy(paramArrayOfByte, 0, arrayOfByte2, this.c - arrayOfByte1, arrayOfByte1);
/*  53: 49 */       a(arrayOfByte2, localStringBuilder);
/*  54:    */     }
/*  55:    */     int i;
/*  56: 52 */     for (byte[] arrayOfByte2 = arrayOfByte1; arrayOfByte2 < paramArrayOfByte.length; arrayOfByte2 += this.c)
/*  57:    */     {
/*  58: 53 */       byte[] arrayOfByte3 = new byte[this.c];
/*  59: 54 */       System.arraycopy(paramArrayOfByte, arrayOfByte2, arrayOfByte3, 0, this.c);
/*  60: 55 */       a(arrayOfByte3, localStringBuilder);
/*  61:    */     }
/*  62: 58 */     return localStringBuilder.toString();
/*  63:    */   }
/*  64:    */   
/*  65:    */   private void a(byte[] paramArrayOfByte, StringBuilder paramStringBuilder)
/*  66:    */   {
/*  67: 62 */     BigInteger localBigInteger1 = new BigInteger(1, paramArrayOfByte);
/*  68: 63 */     if (localBigInteger1.compareTo(this.b) >= 0) {
/*  69: 64 */       throw new IllegalArgumentException("result is too long");
/*  70:    */     }
/*  71: 66 */     BigInteger localBigInteger2 = localBigInteger1.modPow(this.a, this.b);
/*  72: 67 */     paramStringBuilder.append(a(localBigInteger2));
/*  73:    */   }
/*  74:    */   
/*  75:    */   private CharSequence a(BigInteger paramBigInteger)
/*  76:    */   {
/*  77: 71 */     StringBuilder localStringBuilder = new StringBuilder(this.d);
/*  78: 72 */     for (int i = 0; i < this.d; i++)
/*  79:    */     {
/*  80: 73 */       localStringBuilder.append(b(paramBigInteger.mod(this.e)));
/*  81: 74 */       paramBigInteger = paramBigInteger.divide(this.e);
/*  82:    */     }
/*  83: 76 */     return new ReverseCharSequence(localStringBuilder);
/*  84:    */   }
/*  85:    */   
/*  86:    */   private static char b(BigInteger paramBigInteger)
/*  87:    */   {
/*  88: 80 */     int i = paramBigInteger.intValue();
/*  89: 81 */     if (i < 10) {
/*  90: 82 */       return (char)(48 + i);
/*  91:    */     }
/*  92: 84 */     if (i < 36) {
/*  93: 85 */       return (char)(65 + i - 10);
/*  94:    */     }
/*  95: 87 */     if (i < 62) {
/*  96: 88 */       return (char)(97 + i - 36);
/*  97:    */     }
/*  98: 90 */     return (char)(33 + i - 62);
/*  99:    */   }
/* 100:    */   
/* 101:    */   private static class ReverseCharSequence
/* 102:    */     implements CharSequence
/* 103:    */   {
/* 104:    */     private final CharSequence a;
/* 105:    */     
/* 106:    */     public ReverseCharSequence(CharSequence paramCharSequence)
/* 107:    */     {
/* 108: 97 */       this.a = paramCharSequence;
/* 109:    */     }
/* 110:    */     
/* 111:    */     public int length()
/* 112:    */     {
/* 113:102 */       return this.a.length();
/* 114:    */     }
/* 115:    */     
/* 116:    */     public char charAt(int paramInt)
/* 117:    */     {
/* 118:107 */       return this.a.charAt(this.a.length() - paramInt - 1);
/* 119:    */     }
/* 120:    */     
/* 121:    */     @NotNull
/* 122:    */     public CharSequence subSequence(int paramInt1, int paramInt2)
/* 123:    */     {
/* 124:112 */       int i = this.a.length(); void 
/* 125:113 */         tmp32_29 = new ReverseCharSequence(this.a.subSequence(i - paramInt2, i - paramInt1));
/* 126:113 */       if (tmp32_29 == null) {
/* 127:113 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/jetbrains/licenseService/util/RSAEncoder$ReverseCharSequence", "subSequence" }));
/* 128:    */       }
/* 129:113 */       return tmp32_29;
/* 130:    */     }
/* 131:    */   }
/* 132:    */ }



/* Location:           E:\idea\

 * Qualified Name:     com.jetbrains.licenseService.util.RSAEncoder

 * JD-Core Version:    0.7.0.1

 */